<template>
  <div id="content">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/goods_manager' }">商品管理</el-breadcrumb-item>
      <el-breadcrumb-item @click="addCodeInbounch">新增固定编码入库</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>
    <div class="head">
      <el-button class="btn add-btn" @click="isShowAdd = true">新增固定编码入库</el-button>
      <el-button class="btn search-btn" @click="isShowSearch = true">查询</el-button>
    </div>
    <div class="codeAddFrom" v-if="isShowAdd">
      <el-form ref="myForm" :model="postInfo">
        <el-form-item
          v-for="item in selectList1"
          :label="item.title"
          label-width="100px"
          :key="item.id"
          class="title"
          :prop="item.type"
        >
          <el-select
            v-if="item.children"
            style="width:150px"
            size="small"
            v-model="postInfo[item.type]"
          >
            <el-option
              v-for="(info, index) in item.children"
              :key="index"
              :label="info"
              :value="item.title == '来源' ? info: index+1"
            ></el-option>
          </el-select>
          <el-input
            size="small"
            v-else
            v-model="postInfo[item.type]"
            style="width:150px"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="btns">
        <el-button class="btn" type="primary" @click="chooseGoods">选择商品</el-button>
        <el-button class="btn" type="info" @click="hideCodeAddFrom">完成入库</el-button>
      </div>
      <el-table class="box" :data="productDisassemblyOrders" border style="width: 100%">
        <el-table-column label="行号">
          <template slot-scope="scope">{{ scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column prop="status" label="商品编码"></el-table-column>
        <el-table-column prop="documentNum" label="商品名称"></el-table-column>
        <el-table-column prop="createDate" label="模具号"></el-table-column>
        <el-table-column prop="headquartersName" label="电商款号"></el-table-column>
        <el-table-column prop="category" label="款号"></el-table-column>
        <el-table-column prop="count" label="分类1"></el-table-column>
        <el-table-column prop="totalWeight" label="证书1"></el-table-column>
        <el-table-column prop="totalPrice" label="成色"></el-table-column>
        <el-table-column prop="LabelTotalPrice" label="重量"></el-table-column>
        <el-table-column prop="createPerson" label="单件重"></el-table-column>
        <el-table-column prop="approver" label="数量"></el-table-column>
        <el-table-column prop="approvalDate" label="手寸"></el-table-column>
        <el-table-column prop="approvalDate" label="料价"></el-table-column>
        <el-table-column prop="approvalDate" label="销售工费"></el-table-column>
        <el-table-column prop="approvalDate" label="附加费"></el-table-column>
        <el-table-column prop="approvalDate" label="系列名称"></el-table-column>
        <el-table-column prop="approvalDate" label="备注"></el-table-column>
        <el-table-column prop="approvalDate" label="品牌"></el-table-column>
        <el-table-column prop="approvalDate" label="价格类型"></el-table-column>
        <el-table-column prop="approvalDate" label="标签单价"></el-table-column>
        <el-table-column prop="approvalDate" label="成本计价"></el-table-column>
        <el-table-column prop="approvalDate" label="销售计价"></el-table-column>
        <el-table-column prop="approvalDate" label="销售工费计价"></el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" @click="handleClick(scope)" size="small">查看(编辑)</el-button>
            <el-button type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <transition class="transitionBox" name="el-zoom-in-top">
      <div v-if="isShowSearch">
        <el-form ref="myForm" :model="ruleForm">
          <el-form-item
            v-for="item in selectList"
            :label="item.title"
            label-width="80px"
            :key="item.id"
            class="title"
            style="width:240px"
            :prop="item.type"
          >
            <el-select v-if="item.children" size="small" v-model="ruleForm[item.type]">
              <el-option
                v-for="(info, index) in item.children"
                :key="index"
                :label="info"
                :value="info"
              ></el-option>
            </el-select>
            <el-input
              size="small"
              v-else
              v-model="ruleForm[item.type]"
              style="width:160px"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <div class="btns">
          <el-button class="btn" type="primary" @click="confirmSearch">确认查询</el-button>
          <el-button class="btn" type="info" @click="retracting">收起</el-button>
        </div>
      </div>
    </transition>
    <CodeGoodsInbounchList @formDelById="formDelById" :goodsList="codedIntoStorageOrders" />
    <PageComponents :total="total" :curPage="page" />
  </div>
</template>

<script>
import {
  getAllList,
  deleteById,
  addInfos
} from "@/http/codedIntoStorageApi.js";
import CodeGoodsInbounchList from "@/components/inbounchComponents/CodeGoodsInbounchList.vue";
import PageComponents from "@/components/PageComponents.vue";
export default {
  name: "GoodsInbounchStorage",
  components: {
    CodeGoodsInbounchList,
    PageComponents
  },
  created() {
    this.initData();
    this.isFromInventoryStatistics();
  },
  data() {
    return {
      total: 10,
      page: 1,
      isShowSearch: false,
      isShowAdd: false,
      newGoodsList: [],
      ruleForm: {
        documentStartId: "",
        splxid: "",
        supplierid: "",
        shopid: "",
        startCreatetime: "",
        endCreatetime: "",
        orderid: "",
        createperson: "",
        counterid: "",
        from: ""
      },
      postInfo: {
        splxid: "", //商品类型
        from: "", //来源
        shopid: "", //门店id
        createtime: "", //创建时间
        supplierid: "", //供应商id
        orderid: "", //订单号
        counterid: "", //关联柜台表的id
        documentid: "", //单据编号
        createperson: "", //创单人
        idArr: "", // 传递id
        numbers: "" //传递数量
      },
      selectList: [
        {
          id: 1,
          title: "单据编号",
          type: "documentStartId"
        },
        {
          id: 2,
          title: "商品类型",
          children: ["采购", "代销", "联销", "加工", "其他"],
          type: "splxid"
        },
        {
          id: 3,
          title: "供应商",
          children: ["北京总部", "上海分公司"],
          type: "supplierid"
        },
        {
          id: 4,
          title: "入库门店",
          children: ["new Date()"],
          type: "shopid"
        },
        {
          id: 5,
          title: "柜台名称",
          children: ["供应商1", "供应商2"],
          type: "counterid"
        },
        {
          id: 6,
          title: "创单时间1",
          type: "startCreatetime"
        },
        {
          id: 7,
          title: "创单时间2",
          type: "endCreatetime"
        },
        {
          id: 8,
          title: "订单号",
          type: "orderid"
        },
        {
          id: 9,
          title: "来源",
          children: ["3243241", "3243241"],
          type: "from"
        },
        {
          id: 10,
          title: "创单人",
          type: "createperson"
        }
      ],
      selectList1: [
        {
          id: 1,
          title: "商品类型",
          children: ["配饰类", "素金类", "镶嵌类", "其他"],
          type: "splxid"
        },
        {
          id: 2,
          title: "来源",
          children: ["采购", "代销", "联销", "加工", "其他"],
          type: "from"
        },
        {
          id: 3,
          title: "入库门店",
          children: ["北京总部", "上海分公司"],
          type: "shopid"
        },
        {
          id: 4,
          title: "创单日期",
          type: "createtime"
        },
        {
          id: 5,
          title: "供应商",
          children: ["供应商1", "供应商2"],
          type: "supplierid"
        },
        {
          id: 6,
          title: "订单号",
          type: "orderid"
        },
        {
          id: 7,
          title: "柜台/类库名称",
          children: ["配饰柜台", "其他柜台"],
          type: "counterid"
        },
        {
          id: 8,
          title: "单据编号",
          type: "documentid"
        },
        {
          id: 9,
          title: "数量",
          type: "numbers"
        }
      ],
      productDisassemblyOrders: [
        {
          goodsId: 1, // id
          status: 2, // 状态（0：已驳回；1：已通过；2：待审核）
          documentNum: 432, // 单据编号
          createDate: 432432, // 创单时间
          headquartersName: "你无法", // 总部名称
          category: 1, // 商品类型
          count: 1, // 数量
          totalWeight: 1, // 总重量
          totalPrice: 1, // 总成本
          LabelTotalPrice: 1, // 标签总价
          createPerson: "1dewde", // 创单人
          approver: 1, // 审批人
          approvalDate: 123 // 审批日期
        }
      ],
      codedIntoStorageOrders: [
        {
          approver: "郭攀", // 审批人
          approverdate: 1654824349000, // 审批日期
          coefficient: 1, // 系数
          cost: 12, // 成本
          counterid: 1, // 柜台id
          createperson: "金煜", // 创单人
          createtime: 1655283267000, // 创单时间
          documentid: "SPRK202206100908560001", // 单据编号
          fendianname: "望京分店", // 分店名称
          from: "采购", // 来源
          guitainame: "黄金类柜台", // 柜台名称
          id: 2, // id
          labelamount: 1, // 标签金额
          name: "浙商公司", // 供应商名称
          number: 12, // 数量
          orderid: 1, // 订单号
          shopid: 1, // 入库门店id
          splxid: 1, // 商品类型id
          state: 0, //  状态（0：已驳回；1：已通过；2：待审核）
          supplierid: 1, // 供应商id
          typeName: "1", // 商品类型
          weight: 12 // 重量
        }
      ]
    };
  },
  methods: {
    // 收起
    retracting() {
      this.isShowSearch = false;
    },
    // 确认搜索
    confirmSearch() {
      console.log(this.ruleForm);
    },
    // 新增编码入库
    addCodeInbounch() {
      this.isShowAdd = true;
    },
    // 选择商品
    chooseGoods() {
      this.$router.push({
        path: "/goods_manager/inventoryStatistics",
        query: { name: "GoodsInbounchStorage" }
      });
    },
    // 完成入库
    hideCodeAddFrom() {
      this.isShowAdd = false;
      console.log(this.postInfo);
      addInfos(this.postInfo)
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 初始化数据列表
    initData() {
      getAllList()
        .then(res => {
          console.log(res);
          this.codedIntoStorageOrders = res.data.data;
        })
        .catch(err => {
          console.log(err);
        });
      this.postInfo.createperson = localStorage.getItem("username");
    },
    // 删除
    formDelById(id) {
      console.log(id);
      deleteById(id)
        .then(res => {
          console.log(res);
          this.initData();
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 判断是否是从库存统计页面跳转过来的，并初始化数据
    isFromInventoryStatistics() {
      if (this.$route.query.id) {
        this.isShowAdd = true;
        this.postInfo.idArr = this.$route.query.id;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/var.scss";
#content {
  position: relative;
  background: #fff;
  .head {
    margin-bottom: 20px;
    .btn {
      margin-right: 20px;
      background: $theme-color;
      color: #fff;
    }
  }
  .codeAddFrom {
    position: absolute;
    background: #fff;
    top: 172px;
    padding: 20px;
    box-shadow: 0 0 2px #ccc;
    width: 100%;
    // height: 650px;
    z-index: 99;
    .box {
      height: 480px;
      box-shadow: 0 0 2px #ccc;
      overflow-y: scroll;
    }
  }
  .el-form {
    width: 1250px;
    float: left;
    .title {
      float: left;
    }
  }
  .btns {
    height: 80px;
    line-height: 80px;
    float: right;
    margin-right: 80px;
    margin-top: 15px;
    .btn {
      width: 80px;
      height: 80px;
      margin-left: 20px;
      padding: 0;
    }
  }
}
</style>>